package com.huatai.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huatai.user.entity.Role;
import com.huatai.user.vo.PermissionVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<Role> {
	/**
	 * 获取角色选中以及未选中资源权限列表
	 * @param perIds
	 * @return
	 */
	@Select("SELECT *,IF(FIND_IN_SET(id,#{perIds})>0,1,0) as checked FROM sys_permission WHERE is_show=0 ORDER BY sort ASC")
	List<PermissionVo> getRolePermissions(@Param("perIds") String perIds);

	List<PermissionVo> getPermissionChs(@Param("perIds") String perIds,@Param("parent_id") Long parent_id);

	/**
	 * 获取该角色目前资源权限
	 * @param roleId
	 * @return
	 */
	@Select("SELECT DISTINCT permission_id FROM sys_role_permission WHERE role_id=#{roleId}")
	List<Long> getRolePerIds(@Param("roleId") Long roleId);
}
